﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import org.aswing.geom.*;

    public class SoftBoxLayout extends EmptyLayout {

        public static const X_AXIS:int = 0;
        public static const Y_AXIS:int = 1;
        public static const LEFT:int = 2;
        public static const CENTER:int = 0;
        public static const RIGHT:int = 4;
        public static const TOP:int = 1;
        public static const BOTTOM:int = 3;

        private var axis:int;
        private var gap:int;
        private var align:int;

        public function SoftBoxLayout(_arg1:int=0, _arg2:int=0, _arg3:int=2){
            this.setAxis(_arg1);
            this.setGap(_arg2);
            this.setAlign(_arg3);
        }
        public function setAxis(_arg1:int=0):void{
            this.axis = _arg1;
        }
        public function getAxis():int{
            return (this.axis);
        }
        public function setGap(_arg1:int=0):void{
            this.gap = _arg1;
        }
        public function getGap():int{
            return (this.gap);
        }
        public function setAlign(_arg1:int=2):void{
            this.align = _arg1;
        }
        public function getAlign():int{
            return (this.align);
        }
        override public function preferredLayoutSize(_arg1:Container):IntDimension{
            var _local10:Component;
            var _local11:IntDimension;
            var _local12:int;
            var _local2:int = _arg1.getComponentCount();
            var _local3:Insets = _arg1.getInsets();
            var _local4:int;
            var _local5:int;
            var _local6:int;
            var _local7:int;
            var _local8:int;
            while (_local8 < _local2) {
                _local10 = _arg1.getComponent(_local8);
                if (_local10.isVisible()){
                    _local11 = _local10.getPreferredSize();
                    _local4 = Math.max(_local4, _local11.width);
                    _local5 = Math.max(_local5, _local11.height);
                    _local12 = ((_local8 > 0)) ? this.gap : 0;
                    _local6 = (_local6 + (_local11.width + _local12));
                    _local7 = (_local7 + (_local11.height + _local12));
                };
                _local8++;
            };
            if (this.axis == Y_AXIS){
                _local5 = _local7;
            } else {
                _local4 = _local6;
            };
            var _local9:IntDimension = new IntDimension(_local4, _local5);
            return (_local3.getOutsideSize(_local9));
        }
        override public function minimumLayoutSize(_arg1:Container):IntDimension{
            return (_arg1.getInsets().getOutsideSize());
        }
        override public function layoutContainer(_arg1:Container):void{
            var _local10:int;
            var _local11:Component;
            var _local12:IntDimension;
            var _local13:int;
            var _local14:IntDimension;
            var _local15:Component;
            var _local16:IntDimension;
            var _local2:int = _arg1.getComponentCount();
            var _local3:IntDimension = _arg1.getSize();
            var _local4:Insets = _arg1.getInsets();
            var _local5:IntRectangle = _local4.getInsideBounds(_local3.getBounds());
            var _local6:int = _local5.height;
            var _local7:int = _local5.width;
            var _local8:int = _local5.x;
            var _local9:int = _local5.y;
            if ((((this.align == RIGHT)) || ((this.align == BOTTOM)))){
                if (this.axis == Y_AXIS){
                    _local9 = (_local9 + _local6);
                } else {
                    _local8 = (_local8 + _local7);
                };
                _local10 = (_local2 - 1);
                while (_local10 >= 0) {
                    _local11 = _arg1.getComponent(_local10);
                    if (_local11.isVisible()){
                        _local12 = _local11.getPreferredSize();
                        if (this.axis == Y_AXIS){
                            _local9 = (_local9 - _local12.height);
                            _local11.setBounds(new IntRectangle(_local8, _local9, _local7, _local12.height));
                            _local9 = (_local9 - this.gap);
                        } else {
                            _local8 = (_local8 - _local12.width);
                            _local11.setBounds(new IntRectangle(_local8, _local9, _local12.width, _local6));
                            _local8 = (_local8 - this.gap);
                        };
                    };
                    _local10--;
                };
            } else {
                if (this.align == CENTER){
                    _local14 = _local4.getInsideSize(_arg1.getPreferredSize());
                    if (this.axis == Y_AXIS){
                        _local9 = Math.round((_local9 + ((_local6 - _local14.height) / 2)));
                    } else {
                        _local8 = Math.round((_local8 + ((_local7 - _local14.width) / 2)));
                    };
                };
                _local13 = 0;
                while (_local13 < _local2) {
                    _local15 = _arg1.getComponent(_local13);
                    if (_local15.isVisible()){
                        _local16 = _local15.getPreferredSize();
                        if (this.axis == Y_AXIS){
                            _local15.setBounds(new IntRectangle(_local8, _local9, _local7, _local16.height));
                            _local9 = (_local9 + (_local16.height + this.gap));
                        } else {
                            _local15.setBounds(new IntRectangle(_local8, _local9, _local16.width, _local6));
                            _local8 = (_local8 + (_local16.width + this.gap));
                        };
                    };
                    _local13++;
                };
            };
        }
        override public function getLayoutAlignmentX(_arg1:Container):Number{
            return (0.5);
        }
        override public function getLayoutAlignmentY(_arg1:Container):Number{
            return (0.5);
        }

    }
}//package org.aswing 
